package rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.dao.KorisnikDao;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Administrator;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Korisnik;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Vozac;

@SuppressWarnings("serial")
public class PromenaLicnihPodatakaKontroler extends HttpServlet {

	@EJB
	private KorisnikDao cKorisnikDao;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		long jmbg = Long.parseLong(req.getParameter("jmbg"));
		String ime = req.getParameter("ime");
		String prezime = req.getParameter("prezime");

		Korisnik korisnik = (Korisnik) req.getSession()
				.getAttribute("korisnik");
		korisnik.setJmbg(jmbg);
		korisnik.setIme(ime);
		korisnik.setPrezime(prezime);

		cKorisnikDao.stopi(korisnik);
		if (korisnik instanceof Administrator)
			getServletContext().getRequestDispatcher("/PrikazVoznjiKontroler")
					.forward(req, resp);
		else if (korisnik instanceof Vozac)
			getServletContext().getRequestDispatcher(
					"/PrikazNezapocetihVoznjiKontroler").forward(req, resp);
		else
			getServletContext().getRequestDispatcher(
					"/jsp/zahtevanjeVoznje.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
